﻿namespace WMS6.Web.Inbound
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.CommonMethodService2Ref;
    using WMS6.Web.CommonMethodServiceRef;
    using WMS6.Web.InboundServiceRef;

    public class ScanReceiving : BasePage
    {
        protected Button btnConfirm;
        protected Button btnUpdateScanQty;
        protected DropDownList ddlLot09;
        protected HtmlForm F4250;
        protected GridView gvScanReceiving;
        protected GridView gvScanReceivingLpn;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnDataFormat;
        protected HtmlInputHidden hdnGvCss;
        protected HtmlInputHidden hdnIndex;
        protected HtmlInputHidden hdnOwnerID;
        protected HtmlHead Head1;
        protected HtmlInputButton htmlbtnAction;
        protected HtmlInputButton htmlbtnReport;
        protected Label lblASN;
        protected Label lblBadSkuGroup;
        protected Label lblBarcode;
        protected Label lblCaseID;
        protected Label lblExpectedQty;
        protected Label lblExpectedSkuGroup;
        protected Label lblExternalID;
        protected Label lblLot;
        protected Label lblLot01;
        protected Label lblLot09;
        protected Label lblMsg;
        protected Label lblOwnerID;
        protected Label lblPoID;
        protected Label lblProduceDate;
        protected Label lblReceinvingDate;
        protected Label lblReceiptID;
        protected Label lblReceivingQty;
        protected Label lblReceivingSkuGroup;
        protected Label lblSkuDesc;
        protected Label lblSMQty;
        protected Label lblVendorID;
        protected LinkButton lnkbtnAutoputaway;
        protected LinkButton lnkbtnPrintPutAway;
        protected HtmlLink mycss;
        protected ScriptManager ScriptManager1;
        protected HtmlTableCell tdlnkbtnAutoputaway;
        protected HtmlTableCell tdlnkbtnPrintPutAway;
        protected Label TotalBadQty;
        protected Label TotaleExpectedQty;
        protected Label TotalReceivingQty;
        protected TextBox txtBadSkuGroup;
        protected TextBox txtBarcode;
        protected TextBox txtCaseID;
        protected TextBox txtExpectedQty;
        protected TextBox txtExpectedSkuGroup;
        protected TextBox txtExternalID;
        protected TextBox txtLot;
        protected TextBox txtLot01;
        protected TextBox txtOwnerID;
        protected TextBox txtPoID;
        protected TextBox txtProduceDate;
        protected TextBox txtRecedQty;
        protected TextBox txtReceinvingDate;
        protected TextBox txtReceiptID;
        protected TextBox txtReceivingSkuGroup;
        protected TextBox txtSkuDesc;
        protected TextBox txtSMQty;
        protected TextBox txtTotalBadQty;
        protected TextBox txtTotalExpectedQty;
        protected TextBox txtTotalReceivingQty;
        protected TextBox txtVendorID;
        protected UpdatePanel UpdatePanel1;

        private void AutoPutAway()
        {
            this.lblMsg.Visible = false;
            try
            {
                string result = string.Empty;
                List<string> receiptLineID = new List<string>();
                for (int i = 0; i < this.gvScanReceiving.Rows.Count; i++)
                {
                    if (!string.IsNullOrEmpty(((Label) this.gvScanReceiving.Rows[i].FindControl("lblExpectedQty")).Text) && !string.IsNullOrEmpty(((Label) this.gvScanReceiving.Rows[i].FindControl("lblReceivedQty")).Text))
                    {
                        if (decimal.Parse(((Label) this.gvScanReceiving.Rows[i].FindControl("lblReceivedQty")).Text) == decimal.Parse(((Label) this.gvScanReceiving.Rows[i].FindControl("lblExpectedQty")).Text))
                        {
                            receiptLineID.Add(this.gvScanReceiving.DataKeys[i]["ReceiptLineID"].ToString());
                        }
                        else
                        {
                            this.lblMsg.Text = "单据不等于收货完成,无法部分收货!";
                            return;
                        }
                    }
                }
                if ((receiptLineID != null) && (receiptLineID.Count > 0))
                {
                    result = InboundDetailServiceClientProxy.GetInstance().AutoPutAway(this.txtReceiptID.Text, receiptLineID, base.UserInfo.UserID);
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F4200_012");
                    this.lblMsg.Visible = true;
                    return;
                }
                if (!string.IsNullOrEmpty(result))
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F4200_015");
                    this.lblMsg.Visible = true;
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F4200_016");
                    this.lblMsg.Visible = true;
                }
            }
            catch (Exception ex)
            {
                SysLog.GetInstance().LogError(ex);
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>$.unblockUI();</script>", false);
            }
        }

        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            string strtemp = string.Empty;
            try
            {
                if (this.ViewState["ScanReceivingLpn"] != null)
                {
                    List<ReceiptDetailInfo> receiptDetailLpn = this.ViewState["ScanReceivingLpn"] as List<ReceiptDetailInfo>;
                    foreach (ReceiptDetailInfo info in receiptDetailLpn)
                    {
                        ReceiptLotInfo receiptLotInfo = new ReceiptLotInfo {
                            LotAttr01 = info.LotAttr01,
                            LotAttr02 = info.LotAttr02,
                            LotAttr03 = info.LotAttr03,
                            LotAttr04 = info.LotAttr04,
                            LotAttr05 = info.LotAttr05,
                            LotAttr06 = info.LotAttr06,
                            LotAttr07 = info.LotAttr07,
                            LotAttr08 = info.LotAttr08,
                            LotAttr09 = info.LotAttr09,
                            LotAttr10 = info.LotAttr10,
                            ProduceDate = info.ProduceDate,
                            ExternalLot = info.ExternalLot,
                            ReceiptDate = StrUtils.FormatDate(DateTime.Now),
                            VendorID = this.txtVendorID.Text
                        };
                        info.ReceiptLot = receiptLotInfo;
                        info.ReceivedDate = StrUtils.FormatDate(DateTime.Now);
                        info.UomID = "EA";
                        info.ConditionCode = "";
                        info.ReasonCode = "";
                        info.FromLoc = "";
                        info.FromLpnID = info.LpnID;
                        info.ToLpnID = info.LpnID;
                        info.UpdatedBy = base.UserInfo.UserID;
                    }
                    strtemp = InboundServiceClientProxy.GetInstance().ExecuteScanReceiving(receiptDetailLpn);
                    this.lblMsg.Text = "单据扫描收货完成!";
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>$.unblockUI();</script>", false);
            }
        }

        protected void btnUpdateScanQty_Click(object sender, EventArgs e)
        {
            this.txtSMQty.Enabled = true;
        }

        protected void gvScanReceiving_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuDescr"));
                if (string.IsNullOrEmpty(((Label) e.Row.FindControl("lblSkuID")).Text) || (((Label) e.Row.FindControl("lblSkuID")).Text == "&nbsp;"))
                {
                    ((Image) e.Row.FindControl("StatusImg")).Visible = false;
                    ((Label) e.Row.FindControl("lblExpectedQty")).Text = "";
                    ((Label) e.Row.FindControl("lblReceivedQty")).Text = "";
                    ((Label) e.Row.FindControl("lblBadQty")).Text = "";
                    ((Label) e.Row.FindControl("lblHoldQty")).Text = "";
                }
                if (!string.IsNullOrEmpty(((Label) e.Row.FindControl("lblExpectedQty")).Text) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblReceivedQty")).Text))
                {
                    if (decimal.Parse(((Label) e.Row.FindControl("lblReceivedQty")).Text) == decimal.Parse(((Label) e.Row.FindControl("lblExpectedQty")).Text))
                    {
                        ((Image) e.Row.FindControl("StatusImg")).ImageUrl = "~/Images/right.gif";
                    }
                    else
                    {
                        ((Image) e.Row.FindControl("StatusImg")).ImageUrl = "~/Images/wrong.gif";
                    }
                }
                else
                {
                    ((Image) e.Row.FindControl("StatusImg")).ImageUrl = "~/Images/wrong.gif";
                }
            }
        }

        protected void gvScanReceivingLpn_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                if (string.IsNullOrEmpty(((Label) e.Row.FindControl("lblSkuID")).Text) || (((Label) e.Row.FindControl("lblSkuID")).Text == "&nbsp;"))
                {
                    ((Label) e.Row.FindControl("lblReceivedQty")).Text = "";
                }
                base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuDescr"));
            }
        }

        protected void lnkbtnAutoputaway_Click(object sender, EventArgs e)
        {
            this.AutoPutAway();
        }

        protected void lnkbtnPrintPutAway_Click(object sender, EventArgs e)
        {
            this.lblMsg.Visible = false;
            try
            {
                this.Session.Remove("PRINT_PA_TASK_DETAIL_IDS");
                List<string> taskDetailIDs = new List<string>();
                List<PrintControlInfo> printControlInfos = new List<PrintControlInfo>();
                taskDetailIDs = InboundDetailServiceClientProxy.GetInstance().GetUnPrintPutawayTaskIDByReceiptID(this.txtReceiptID.Text.Trim());
                foreach (string taskDetailID in taskDetailIDs)
                {
                    PrintControlInfo printControlInfo = new PrintControlInfo {
                        PrintType = "PrintPutaway",
                        DocID = this.txtReceiptID.Text.Trim(),
                        DocLineID = taskDetailID
                    };
                    printControlInfos.Add(printControlInfo);
                }
                if (taskDetailIDs.Count <= 0)
                {
                    this.lblMsg.Text = "没有可打印的记录.";
                    this.lblMsg.Visible = true;
                }
                else
                {
                    this.Session["PRINT_PA_TASK_DETAIL_IDS"] = taskDetailIDs;
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',4,4);popPrintPutAway();</script>", false);
                    CommoneMethodService2ClientProxy.GetInstance().SavePrintControl(printControlInfos);
                }
            }
            catch (Exception ex)
            {
                SysLog.GetInstance().LogError(ex);
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',4,4);</script>", false);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.ViewState["ScanReceiving"] = new List<ReceiptDetailInfo>();
                base.BindData2GridView(this.gvScanReceiving, this.SetGvidViewRow(new List<ReceiptDetailInfo>(), 5));
                base.BindData2GridView(this.gvScanReceivingLpn, this.SetGvidViewRow(new List<ReceiptDetailInfo>(), 10));
                this.ViewState["ScanReceivingLpn"] = new List<ReceiptDetailInfo>();
                this.ViewState["SkuGroup"] = new List<string>();
                this.ViewState["SkuGroupBad"] = new List<string>();
                base.BindData2DDLBySysCode(this.ddlLot09, "ConditionCode");
                this.txtReceiptID.Focus();
            }
            this.lblMsg.Text = "";
        }

        private void SetGridViewCss(GridView gv, int index)
        {
            for (int i = 0; gv.Rows.Count > i; i++)
            {
                if (gv.Rows[i].CssClass == "GridViewRowAutoSelectStyle")
                {
                    gv.Rows[i].CssClass = this.hdnGvCss.Value;
                }
                if (i == index)
                {
                    this.hdnGvCss.Value = gv.Rows[i].CssClass;
                    gv.Rows[i].CssClass = "GridViewRowAutoSelectStyle";
                }
            }
        }

        private List<ReceiptDetailInfo> SetGvidViewRow(List<ReceiptDetailInfo> ReceiptDetailInfoList, int rowCount)
        {
            if (ReceiptDetailInfoList == null)
            {
                ReceiptDetailInfoList = new List<ReceiptDetailInfo>();
            }
            for (int i = ReceiptDetailInfoList.Count<ReceiptDetailInfo>(); i < rowCount; i++)
            {
                ReceiptDetailInfo ReceiptDetailInfo = new ReceiptDetailInfo();
                ReceiptDetailInfoList.Add(ReceiptDetailInfo);
            }
            return ReceiptDetailInfoList;
        }

        protected void txtBarcode_OnTextChanged(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(this.txtSMQty.Text))
                {
                    this.lblMsg.Text = "请输入扫描数量！";
                    this.txtSMQty.Focus();
                }
                else if (!string.IsNullOrEmpty(this.txtBarcode.Text))
                {
                    decimal Qty = decimal.Parse(this.txtSMQty.Text);
                    string strSkuID = string.Empty;
                    bool IsReview = false;
                    SkuInfo skuInfo = CommoneMethodServiceClientProxy.GetInstance().GetSkuByBarcode(this.txtBarcode.Text);
                    if (skuInfo != null)
                    {
                        if (this.ViewState["ScanReceivingLpn"] != null)
                        {
                            List<ReceiptDetailInfo> ReceiptDetailLpnList = this.ViewState["ScanReceivingLpn"] as List<ReceiptDetailInfo>;
                            if (ReceiptDetailLpnList != null)
                            {
                                foreach (ReceiptDetailInfo info in ReceiptDetailLpnList)
                                {
                                    if (!string.IsNullOrEmpty(info.SkuID) && (skuInfo.SkuID.ToUpper() == info.SkuID.ToUpper()))
                                    {
                                        strSkuID = skuInfo.SkuID;
                                        if (info.ExpectedQty >= (info.ReceivedQty + Qty))
                                        {
                                            this.txtCaseID.Text = info.LpnID;
                                            this.txtSkuDesc.Text = skuInfo.Descr;
                                            info.ToLoc = skuInfo.PutawayLoc;
                                            if (!string.IsNullOrEmpty(this.txtProduceDate.Text))
                                            {
                                                info.ProduceDate = Convert.ToDateTime(this.txtProduceDate.Text);
                                            }
                                            ReceiptDetailInfo receiptDetailinfo = null;
                                            bool isSame = false;
                                            int index = 0;
                                            if (((info.LotAttr01 != this.txtLot01.Text) || (info.ExternalLot != this.txtLot.Text)) || (info.LotAttr09 != this.ddlLot09.SelectedValue))
                                            {
                                                if ((info.ExpectedQty == Qty) && (info.ReceivedQty == 0M))
                                                {
                                                    info.ReceivedQty += Qty;
                                                    info.LotAttr09 = this.ddlLot09.SelectedValue;
                                                    info.LotAttr01 = this.txtLot01.Text;
                                                    info.ExternalLot = this.txtLot.Text;
                                                }
                                                else
                                                {
                                                    foreach (ReceiptDetailInfo infos in ReceiptDetailLpnList)
                                                    {
                                                        if ((((info.LpnID == infos.LpnID) && (this.txtLot01.Text == infos.LotAttr01)) && (this.txtLot.Text == infos.ExternalLot)) && (this.ddlLot09.SelectedValue == infos.LotAttr09))
                                                        {
                                                            receiptDetailinfo = new ReceiptDetailInfo();
                                                            receiptDetailinfo.EffectiveDate = infos.EffectiveDate;
                                                            receiptDetailinfo.ExpectedQty = infos.ExpectedQty;
                                                            receiptDetailinfo.ExpiryDate = infos.ExpiryDate;
                                                            receiptDetailinfo.ExternalLot = infos.ExternalLot;
                                                            receiptDetailinfo.ExternLineID = infos.ExternLineID;
                                                            receiptDetailinfo.ExternReceiptID = infos.ExternReceiptID;
                                                            receiptDetailinfo.FromLoc = infos.FromLoc;
                                                            receiptDetailinfo.FromLpnID = infos.FromLpnID;
                                                            receiptDetailinfo.LotAttr01 = infos.LotAttr01;
                                                            receiptDetailinfo.LotAttr02 = infos.LotAttr02;
                                                            receiptDetailinfo.LotAttr03 = infos.LotAttr03;
                                                            receiptDetailinfo.LotAttr04 = infos.LotAttr04;
                                                            receiptDetailinfo.LotAttr05 = infos.LotAttr05;
                                                            receiptDetailinfo.LotAttr06 = infos.LotAttr06;
                                                            receiptDetailinfo.LotAttr07 = infos.LotAttr07;
                                                            receiptDetailinfo.LotAttr08 = infos.LotAttr08;
                                                            receiptDetailinfo.LotAttr09 = infos.LotAttr09;
                                                            receiptDetailinfo.LotAttr10 = infos.LotAttr10;
                                                            receiptDetailinfo.LpnID = infos.LpnID;
                                                            receiptDetailinfo.OwnerID = infos.OwnerID;
                                                            receiptDetailinfo.PackID = infos.PackID;
                                                            receiptDetailinfo.PoID = infos.PoID;
                                                            receiptDetailinfo.PoLineID = infos.PoLineID;
                                                            receiptDetailinfo.ProduceDate = infos.ProduceDate;
                                                            receiptDetailinfo.Remark = infos.Remark;
                                                            receiptDetailinfo.SkuDescr = infos.SkuDescr;
                                                            receiptDetailinfo.SkuID = infos.SkuID;
                                                            receiptDetailinfo.Status = infos.Status;
                                                            receiptDetailinfo.ToLoc = infos.ToLoc;
                                                            receiptDetailinfo.ToLpnID = infos.ToLpnID;
                                                            receiptDetailinfo.ToLot = infos.ToLot;
                                                            receiptDetailinfo.ExpectedQty = infos.ExpectedQty + Qty;
                                                            receiptDetailinfo.ReceivedQty = infos.ReceivedQty + Qty;
                                                            isSame = true;
                                                            break;
                                                        }
                                                        index++;
                                                    }
                                                    if (!isSame)
                                                    {
                                                        receiptDetailinfo = new ReceiptDetailInfo {
                                                            EffectiveDate = info.EffectiveDate,
                                                            ExpectedQty = info.ExpectedQty,
                                                            ExpiryDate = info.ExpiryDate,
                                                            ExternalLot = this.txtLot.Text,
                                                            ExternLineID = info.ExternLineID,
                                                            ExternReceiptID = info.ExternReceiptID,
                                                            FromLoc = info.FromLoc,
                                                            FromLpnID = info.FromLpnID,
                                                            LotAttr01 = this.txtLot01.Text,
                                                            LotAttr02 = info.LotAttr02,
                                                            LotAttr03 = info.LotAttr03,
                                                            LotAttr04 = info.LotAttr04,
                                                            LotAttr05 = info.LotAttr05,
                                                            LotAttr06 = info.LotAttr06,
                                                            LotAttr07 = info.LotAttr07,
                                                            LotAttr08 = info.LotAttr08,
                                                            LotAttr09 = this.ddlLot09.SelectedValue,
                                                            LotAttr10 = info.LotAttr10,
                                                            LpnID = info.LpnID,
                                                            OwnerID = info.OwnerID,
                                                            PackID = info.PackID,
                                                            PoID = info.PoID,
                                                            PoLineID = info.PoLineID
                                                        };
                                                        if (!string.IsNullOrEmpty(this.txtProduceDate.Text))
                                                        {
                                                            receiptDetailinfo.ProduceDate = Convert.ToDateTime(this.txtProduceDate.Text);
                                                        }
                                                        else
                                                        {
                                                            receiptDetailinfo.ProduceDate = info.ProduceDate;
                                                        }
                                                        receiptDetailinfo.Remark = info.Remark;
                                                        receiptDetailinfo.SkuDescr = info.SkuDescr;
                                                        receiptDetailinfo.SkuID = info.SkuID;
                                                        receiptDetailinfo.Status = info.Status;
                                                        receiptDetailinfo.ToLoc = info.ToLoc;
                                                        receiptDetailinfo.ToLpnID = info.ToLpnID;
                                                        receiptDetailinfo.ToLot = info.ToLot;
                                                        receiptDetailinfo.ExpectedQty = Qty;
                                                        receiptDetailinfo.ReceivedQty = Qty;
                                                        //info.ExpectedQty = decimal.op_Decrement(info.ExpectedQty);
                                                        info.ExpectedQty = --info.ExpectedQty;
                                                    }
                                                    else
                                                    {
                                                        ReceiptDetailLpnList.RemoveAt(index);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                info.LotAttr09 = this.ddlLot09.SelectedValue;
                                                info.LotAttr01 = this.txtLot01.Text;
                                                info.ExternalLot = this.txtLot.Text;
                                                info.ReceivedQty += Qty;
                                            }
                                            this.txtRecedQty.Text = info.ReceivedQty.ToString();
                                            ReceiptDetailLpnList.Remove(info);
                                            ReceiptDetailLpnList.Insert(0, info);
                                            if (receiptDetailinfo != null)
                                            {
                                                ReceiptDetailLpnList.Insert(0, receiptDetailinfo);
                                            }
                                            IsReview = true;
                                            break;
                                        }
                                        IsReview = false;
                                    }
                                }
                                this.ViewState["ScanReceivingLpn"] = ReceiptDetailLpnList;
                                base.BindData2GridView(this.gvScanReceivingLpn, this.SetGvidViewRow(ReceiptDetailLpnList, 10));
                                this.SetGridViewCss(this.gvScanReceivingLpn, 0);
                                List<string> strSkuGroup = this.ViewState["SkuGroup"] as List<string>;
                                List<string> strSkuGroupBad = this.ViewState["SkuGroupBad"] as List<string>;
                                if (this.ViewState["ScanReceiving"] != null)
                                {
                                    List<ReceiptDetailInfo> ReceiptDetail = this.ViewState["ScanReceiving"] as List<ReceiptDetailInfo>;
                                    if (IsReview)
                                    {
                                        foreach (ReceiptDetailInfo info in ReceiptDetail)
                                        {
                                            if (!string.IsNullOrEmpty(info.SkuID) && (info.SkuID.ToUpper() == strSkuID.ToUpper()))
                                            {
                                                if (!strSkuGroup.Contains(info.SkuID.ToUpper()))
                                                {
                                                    strSkuGroup.Add(info.SkuID.ToUpper());
                                                }
                                                if (info.ExpectedQty >= (info.ReceivedQty + Qty))
                                                {
                                                    decimal CS00003 = decimal.Parse(this.txtTotalReceivingQty.Text) + Qty;
                                                    this.txtTotalReceivingQty.Text = CS00003.ToString();
                                                    info.ReceivedQty += Qty;
                                                    this.txtExpectedQty.Text = info.ExpectedQty.ToString();
                                                    if (this.ddlLot09.SelectedValue == "Hold")
                                                    {
                                                        info.HoldQty += Convert.ToInt32(Qty);
                                                    }
                                                    if (this.ddlLot09.SelectedValue == "Damage")
                                                    {
                                                        if (!strSkuGroupBad.Contains(info.SkuID))
                                                        {
                                                            strSkuGroupBad.Add(info.SkuID);
                                                        }
                                                        info.BadQty += Convert.ToInt32(Qty);
                                                        this.txtTotalBadQty.Text = (decimal.Parse(this.txtTotalBadQty.Text) + Qty).ToString();
                                                    }
                                                    ReceiptDetail.Remove(info);
                                                    ReceiptDetail.Insert(0, info);
                                                    break;
                                                }
                                            }
                                        }
                                        this.txtReceivingSkuGroup.Text = strSkuGroup.Count<string>().ToString();
                                        this.txtBadSkuGroup.Text = strSkuGroupBad.Count<string>().ToString();
                                        this.ViewState["SkuGroup"] = strSkuGroup;
                                        this.ViewState["SkuGroupBad"] = strSkuGroupBad;
                                        this.ViewState["ScanReceiving"] = ReceiptDetail;
                                        base.BindData2GridView(this.gvScanReceiving, this.SetGvidViewRow(ReceiptDetail, 5));
                                        this.SetGridViewCss(this.gvScanReceiving, 0);
                                    }
                                }
                            }
                        }
                        if (!IsReview)
                        {
                            this.lblMsg.Text = "扫描货品扫描数量大于码盘行项收货数量,无法继续收货!";
                            this.txtBarcode.Focus();
                        }
                    }
                    else
                    {
                        this.lblMsg.Text = "未找到匹配的货品请检查条码!";
                        this.txtBarcode.Focus();
                    }
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.txtBarcode.Focus();
            }
            finally
            {
                this.txtBarcode.Text = "";
                this.txtBarcode.Focus();
            }
        }

        protected void txtReceiptID_OnTextChanged(object sender, EventArgs e)
        {
            ReceiptInfo receiptInfo = null;
            try
            {
                if (!string.IsNullOrEmpty(this.txtReceiptID.Text))
                {
                    receiptInfo = InboundServiceClientProxy.GetInstance().GetReceiptScanReceivingByID(this.txtReceiptID.Text);
                    if (((receiptInfo != null) && (receiptInfo.ReceiptDetailInfos != null)) && (receiptInfo.ReceiptDetailInfos.Count > 0))
                    {
                        if (receiptInfo.Status.ToUpper() == "NEW")
                        {
                            this.hdnOwnerID.Value = receiptInfo.OwnerID;
                            this.txtPoID.Text = receiptInfo.PoID;
                            this.txtExternalID.Text = receiptInfo.ExternalReceiptID;
                            this.txtReceinvingDate.Text = base.GetPreferenceShortDate(receiptInfo.ReceiptDate);
                            this.txtVendorID.Text = receiptInfo.VendorID;
                            this.txtOwnerID.Text = receiptInfo.OwnerID;
                            List<string> skuGroupCount = new List<string>();
                            decimal totalQty = 0M;
                            foreach (ReceiptDetailInfo info in receiptInfo.ReceiptDetailInfos)
                            {
                                if (!skuGroupCount.Contains(info.SkuID))
                                {
                                    skuGroupCount.Add(info.SkuID);
                                }
                                totalQty += info.ExpectedQty;
                            }
                            this.txtExpectedSkuGroup.Text = skuGroupCount.Count<string>().ToString();
                            this.txtTotalExpectedQty.Text = totalQty.ToString();
                            this.hdnIndex.Value = "0";
                            goto Label_0212;
                        }
                        this.lblMsg.Text = "单据状态不等于新建无法收货!";
                        this.txtReceiptID.Text = "";
                        this.txtReceiptID.Focus();
                    }
                    else
                    {
                        this.lblMsg.Text = "未找到匹配的数据!";
                        this.txtReceiptID.Text = "";
                        this.txtReceiptID.Focus();
                    }
                }
                return;
            Label_0212:
                this.ViewState["ScanReceiving"] = receiptInfo.ReceiptDetailInfos;
                base.BindData2GridView(this.gvScanReceiving, this.SetGvidViewRow(receiptInfo.ReceiptDetailInfos, 5));
                this.SetGridViewCss(this.gvScanReceiving, 0);
                this.ViewState["ScanReceivingLpn"] = receiptInfo.ReceiptDetailLpnInfos;
                base.BindData2GridView(this.gvScanReceivingLpn, this.SetGvidViewRow(receiptInfo.ReceiptDetailLpnInfos, 10));
                this.SetGridViewCss(this.gvScanReceivingLpn, 0);
                this.txtBarcode.Focus();
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }
    }
}

